import numpy as np
np.set_printoptions(suppress=True)

input_example = [[-0.783778, 1.783778, 0.026, 0.0, 0.000431, 0.002889, 0.000444, 0.059111, 0.100889, 2145302.755556, 0.135066, 0.004496, 0.073298, 0.864934, 0.003251, 0.004196, 1225196032.0, 498422272.0, 35434.666667, 36029.866667, 23257771.25, 2145302.755556],
 [-0.863111, 1.863111, 0.072889, 0.0, 0.0, 0.000889, 0.0, 0.026222, 0.030667, 563609.6, 0.079898, 0.003494, 0.048774, 0.920102, 0.005568, 0.00384, 616874496.0, 967455232.0, 2587.2, 3118.066667, 3363980.0, 563609.6],
 [-0.773778, 1.773778, 0.155333, 0.0, 0.0, 0.000444, 0.0, 0.024889, 0.036, 6830671.644444, 0.081268, 0.00348, 0.049573, 0.918732, 0.005644, 0.003863, 634319360.0, 965734912.0, 2614.533333, 3022.066667, 3338474.5, 6830671.644444],
 [-0.777333, 1.777333, 0.018889, 0.0, 0.000222, 0.003556, 0.0, 0.054, 0.110667, 8691165.866667, 0.15591, 0.006623, 0.088744, 0.84409, 0.003981, 0.004622, 1398518272.0, 1943880192.0, 31833.466667, 32364.333333, 23702986.0, 8691165.866667]]

output_example = [[0.88805928, 0.11194072, 0.05211662, float('nan'), 1., 0.78566838,
 1., 1., 0.877775,   0.1946087,  0.72578014, 0.32325803,
  0.61356017, 0.27421986, 0., 0.45524297, 0.7782593,  0.,
  1., 1., 0.97813772, 0.1946087],
 [0., 1., 0.39576676, float('nan'), 0., 0.14299486,
  0., 0.03895155, 0., 0., 0., 0.00445434,
  0., 1., 0.9682407, 0., 0., 0.32448745,
  0., 0.0029084, 0.00125245, 0.],
 [1., 0., 1., float('nan'), 0., 0.,
  0., 0., 0.0666625,  0.77108812, 0.01802347, 0.,
  0.01998999, 0.98197653, 1., 0.02941176, 0.02231818, 0.3232973,
  0.00083213, 0., 0., 0.77108812],
 [0.96020508, 0.03979492, 0., float('nan'), 0.51508121, 1.,
  0., 0.85065163, 1., 1., 1., 1.,
  1., 0., 0.30505641, 1., 1., 1.,
  0.89036597, 0.88894948, 1., 1.]]


def compare(o_e, o):
    assert isinstance(o_e, np.ndarray)
    assert isinstance(o, np.ndarray)

    if o_e.shape == o.shape:
        for i in range(0, o_e.shape[0]):
            for j in range(0, o_e.shape[1]):
                if np.isnan(o_e[i, j]):
                    pass
                else:
                    if round(float(o[i, j]), 8) != o_e[i, j]:
                        print(o[i, j])
                        print(o_e[i, j])
                        print(str(i) + "-" + str(j))
                        return False
        return True
    else:
        return False


def ourpreprocess(temp_arr):
    no=temp_arr.shape[1]
    DSIZE=temp_arr.shape[0]
    for num in range(0,no):
        value=temp_arr[:,num]
        npArray=dataPreprocess(value,DSIZE)
        temp_arr[:, num]=npArray
    return temp_arr

def dataPreprocess(npArray,DSIZE):
    # min-max标准化   离差标准化，是对原始数据的线性变换，使结果值映射到[0 - 1]之间
    npArray = [(x - min(npArray)) / (max(npArray) - min(npArray)) for x in npArray]
    return npArray

# 用例目的
print("该用例目的为：")
print("进行数据标准化处理组件功能测试，测试组件在正常输入下能否获得正确结果，矩阵各位置数值在[0-1]范围内")

# 子用例编号
print("子用例编号：")
print("Standardization_2")

print("****************************")
print("当前输入为：")
# 输出用例设置
print(input_example)
# 输出用例设置

print("")

print("****************************")
print("当前输出为:")
# 输出处理后数据
output = ourpreprocess(np.array(input_example))
print(output)
# 输出处理后数据

print("****************************")
print("是否正确:")
# 输出对比结果
# 需要写一个compare函数
if compare(np.array(output_example), output):
    print("输出与预定目标相符")
else:
    print("输出与预定目标不符")
# 输出对比结果

print("\n")
